
using System.Web.UI.HtmlControls;
using System;
using System.Configuration;
using System.Drawing;
using System.Data;
using System.Web.UI.WebControls;
using Microsoft.VisualBasic;
using System.Collections;
using System.Web.UI;
using System.Web;


using System.Resources;
using ddscControlLibrary;
using Microsoft.Web.UI.WebControls;
using SMAS;
using System.Net.Mail;

using DDSC.OracleADO;
using com.ddsc.common;


namespace smasb2b
{
    [Serializable()]
    public class VENDOR
	{
		public string VENDOR_NO;
		public string VENDOR_TYPE;
		public string NAME;
		public string ENGLISH_NAME;
		public string PASSWORD;
		public string E_MAIL1;
		public string E_MAIL2;
		public string E_MAIL3;
		public string B2BE_MAIL1;
		public string B2BE_MAIL2;
		public string B2BE_MAIL3;
		
		public string B2B_STATUS;
		public string B2B_FLAG_STATUS;
		public string VENDOR_STATUS;
		public string PW_STATUS;
		public string VENDOR_KIND;
		public string CURRENCY_TYPE;
		public bool IsAutouth;
	}
	public class BasePage : System.Web.UI.Page
	{
		public BasePage()
		{
			// VBConversions Note: Non-static class variable initialization is below.  Class variables cannot be initially assigned non-static values in C#.
			SystemDate = DateTime.Now.ToString("yyyyMMdd");
			SystemTime = DateTime.Now.ToString("HHmmss");
			
		}
		
		public string oldChar;
		public string newChar;
		public bool IsReSubmit = false;
		public int PageSize = 10;
		public string SystemDate; // VBConversions Note: Initial value cannot be assigned here since it is non-static.  Assignment has been moved to the class constructors.
		public string SystemTime; // VBConversions Note: Initial value cannot be assigned here since it is non-static.  Assignment has been moved to the class constructors.
		
		public dynamic CreareHtmlCell()
		{
			dynamic returnValue = default(dynamic);
			HtmlTableCell TableCell = new HtmlTableCell();
			TableCell.Attributes.Add("class", "detail");
			returnValue = TableCell;
			return returnValue;
		}
		
		public string CreaterInnerHTML(string type, string name, string size, string value, bool @checked, string onchange, string onclick, bool IsReadOnly, string TypeMode, string DataFormat, string ID, string MaxLength, System.Data.DataTable dbSource = null, string sTextField = "", string sValueField = "", int iSelect = 0, string chk1 = "", string chk2 = "", string chk3 = "")
		{
            string returnValue = default(string);
			try
			{
				switch (type.ToLower())
				{
					case "input":
						if (TypeMode == "number")
						{
							if (!IsReadOnly)
							{
								returnValue = string.Format("<input type=\'{0}\' size=\'{1}\' name=\'{2}\' value=\'{3}\'  onchange=\'{4}\' onclick=\'{5}\' class=\'number\' style=\'width: 100%\' TypeMode=\'{6}\' DataFormat=\'{7}\' ID=\'{8}\' MaxLength=\'{9}\'  AllowEmpty=\'True\'>", type, size, name, value, onchange, onclick, TypeMode, DataFormat, ID, MaxLength);
							}
							else
							{
								returnValue = string.Format("<input type=\'{0}\' size=\'{1}\' name=\'{2}\' value=\'{3}\'  onchange=\'{4}\' onclick=\'{5}\' readonly tabIndex=-1 style=\'width: 100%\' class=\'number-readonly\' TypeMode=\'{6}\' DataFormat=\'{7}\' ID=\'{8}\' MaxLength=\'{9}\' AllowEmpty=\'True\'>", type, size, name, value, onchange, onclick, TypeMode, DataFormat, ID, MaxLength);
							}
						}
						else
						{
							if (!IsReadOnly)
							{
								returnValue = string.Format("<input type=\'{0}\' size=\'{1}\' name=\'{2}\' value=\'{3}\'  onchange=\'{4}\' onclick=\'{5}\' class=\'text\' style=\'width: 100%\' TypeMode=\'{6}\' DataFormat=\'{7}\' ID=\'{8}\' MaxLength=\'{9}\'  AllowEmpty=\'True\'>", type, size, name, value, onchange, onclick, TypeMode, DataFormat, ID, MaxLength);
							}
							else
							{
								returnValue = string.Format("<input type=\'{0}\' size=\'{1}\' name=\'{2}\' value=\'{3}\'  onchange=\'{4}\' onclick=\'{5}\' readonly tabIndex=-1 style=\'width: 100%\' class=\'readonly\' TypeMode=\'{6}\' DataFormat=\'{7}\' ID=\'{8}\' MaxLength=\'{9}\' AllowEmpty=\'True\'>", type, size, name, value, onchange, onclick, TypeMode, DataFormat, ID, MaxLength);
							}
							
						}
						break;
						
					case "hidden":
						returnValue = string.Format("<input type=\'{0}\' size=\'{1}\' name=\'{2}\'  value=\'{3}\' ID=\'{4}\'>", type, size, name, value, ID);
						break;
					case "button":
						if (!IsReadOnly)
						{
							returnValue = string.Format("<input type=\'{0}\' size=\'{1}\' name=\'{2}\' value=\'{3}\'  onclick=\'{4}\' style=\'width: 100%;DISPLAY= ;\'   ID=\'{5}\'  >", type, size, name, value, onclick, ID);
						}
						else
						{
							returnValue = string.Format("<input type=\'{0}\' size=\'{1}\' name=\'{2}\' value=\'{3}\'  onclick=\'{4}\' readonly tabIndex=-1  style=\'width: 100%;DISPLAY= none;\'  class=\'readonly\'  ID=\'{5}\'  >", type, size, name, value, onclick, ID);
						}
						break;
					case "select":
						int i = 0;
						if (!IsReadOnly)
						{
							returnValue = string.Format("<select name=\'{0}\' ID=\'{1}\' onchange=\'{2}\' datasource=\'{3}\' datatextfield=\'{4}\' datavaluefield=\'{5}\' style=\'width:100%;\'>", name, ID, onchange, dbSource, sTextField, sValueField, size);
							for (i = 0; i <= dbSource.Rows.Count; i++)
							{
								if (i == 0)
								{
									if (iSelect == 1)
									{
										returnValue = returnValue + "<OPTION selected value=\'\'></OPTION>";
									}
									else
									{
										//CreaterInnerHTML = CreaterInnerHTML + "<OPTION selected value=" + chk1 + ">" + chk1 + "</OPTION>"
									}
								}
								else
								{
									if (dbSource.Rows[i - 1][sValueField] == value)
									{
										
										returnValue = returnValue + "<OPTION selected value=" + dbSource.Rows[i - 1][sValueField] + ">" + dbSource.Rows[i - 1][sTextField] + " </OPTION>";
									}
									else
									{
										returnValue = returnValue + "<OPTION value=" + dbSource.Rows[i - 1][sValueField] + ">" + dbSource.Rows[i - 1][sTextField] + " </OPTION>";
									}
								}
							}
							
						}
						else
						{
							returnValue = string.Format("<select name=\'{0}\' ID=\'{1}\' onclick=\'{2}\' datasource=\'{3}\' datatextfield=\'{4}\' datavaluefield=\'{5}\' style=\'width:100%;\' disabled   >", name, ID, onclick, dbSource, sTextField, sValueField, size);
							for (i = 0; i <= dbSource.Rows.Count; i++)
							{
								if (i == 0)
								{
									if (iSelect == 1)
									{
										returnValue = returnValue + "<OPTION selected value=\'\'></OPTION>";
									}
								}
								else
								{
									if (dbSource.Rows[i - 1][sValueField] == value)
									{
										
										returnValue = returnValue + "<OPTION selected value=" + dbSource.Rows[i - 1][sValueField] + ">" + dbSource.Rows[i - 1][sTextField] + " </OPTION>";
									}
									else
									{
										returnValue = returnValue + "<OPTION value=" + dbSource.Rows[i - 1][sValueField] + ">" + dbSource.Rows[i - 1][sTextField] + " </OPTION>";
									}
								}
							}
						}
						returnValue = returnValue + "</select>";
						break;
					case "checkbox":
						if (ID == "chkSTATUS")
						{
							onclick = "CheckStatus()";
						}
						if (@checked)
						{
							if (!IsReadOnly)
							{
								returnValue = string.Format("<input type=\'{0}\' value=\'{1}\' name=\'{2}\' ID=\'{3}\' onClick=\'{4}\' checked=true >", type, value, name, ID, onclick);
							}
							else
							{
								returnValue = string.Format("<input type=\'{0}\' value=\'{1}\' name=\'{2}\' ID=\'{3}\' onClick=\'{4}\' checked=true disabled>", type, value, name, ID, onclick);
							}
						}
						else
						{
							if (!IsReadOnly)
							{
								returnValue = string.Format("<input type=\'{0}\' value=\'{1}\' name=\'{2}\' ID=\'{3}\' onClick=\'{4}\'>", type, value, name, ID, onclick);
							}
							else
							{
								returnValue = string.Format("<input type=\'{0}\' value=\'{1}\' name=\'{2}\' ID=\'{3}\' onClick=\'{4}\' disabled>", type, value, name, ID, onclick);
							}
						}
						break;
						
					case "radio":
						if (!IsReadOnly)
						{
							returnValue = string.Format("<table id=\'{0}\' border=\'0\'> <tr><td> <input type=\'{1}\' value=\'{2}\' name=\'{3}\' ID=\'{4}\' {5} > <lable for= {6} > {7} </label></td><td><input type=\'{8}\' value=\'{9}\' name=\'{10}\' ID=\'{11}\' {12} > <lable for=\'{13}\' > {14} </label></td> </tr></table> ", name, type, value, name, ID + "_1", chk1, ID + "_1", "是", type, 2, name, ID + "_2", chk2, ID + "_2", "否");
							
						}
						else
						{
							returnValue = string.Format("<table id=\'{0}\' border=\'0\'> <tr><td> <input type=\'{1}\' value=\'{2}\' name=\'{3}\' ID=\'{4}\' {5} disabled > <lable for= {6} > {7} </label></td><td><input type=\'{8}\' value=\'{9}\' name=\'{10}\' ID=\'{11}\' {12}  disabled > <lable for=\'{13}\' > {14} </label></td> </tr></table> ", name, type, value, name, ID + "_1", chk1, ID + "_1", "是", type, 2, name, ID + "_2", chk2, ID + "_2", "否");
							
						}
						break;
						//<td><input id="RadioButtonList1_0" type="radio" name="RadioButtonList1" value="1" /><label for="RadioButtonList1_0">是</label></td><td><input id="RadioButtonList1_1" type="radio" name="RadioButtonList1" value="2" /><label for="RadioButtonList1_1">否</label></td>
						
				}
			}
			catch (Exception)
			{
				returnValue = "";
			}
			return returnValue;
		}
		
		
		protected override void OnLoad(System.EventArgs e)
		{
			
			// 取得多國語言預設值
			if (!(Request["Language"] == null))
			{
				Session["langauage"] = Request["Language"];
			}
			if (Session["langauage"] == null)
			{
				Session["langauage"] = "zh-tw";
			}
			
			Control ControlItem = default(Control);
			rm = GetResourceManager();
			//多國語言轉換
			foreach (Control tempLoopVar_ControlItem in Page.Controls)
			{
				ControlItem = tempLoopVar_ControlItem;
				switch (ControlItem.GetType().Name)
				{
					case "HtmlForm":
						TransformLanguage(ControlItem);
						break;
				}
			}



            InnertScript("{F3AE6520-1ED9-4422-B1FD-22B75BF7DDBI}", " <link href=\'/smasb2b/css/jquery-ui-1.9.2.custom.min.css\' rel=\'stylesheet\' />");
            InnertScript("{F3AE6520-1ED9-4422-B1FD-22B75BF7DDBJ}", "<script src=\'/smasb2b/js/jquery-1.11.1.min.js\'></script>");
            InnertScript("{F3AE6520-1ED9-4422-B1FD-22B75BF7DDBK}", "<script src=\'/smasb2b/js/jquery-ui-1.9.2.custom.min.js\'></script>");

			InnertScript("{F3AE6520-1ED9-4422-B1FD-22B75BF7DDBA}", "<script src=\'/smasb2b/js/FunctionHandler.js\'></script>");
			InnertScript("{F3AE6520-1ED9-4422-B1FD-22B75BF7DDBB}", "<script src=\'/smasb2b/js/date.js\'></script>");
			InnertScript("{F3AE6520-1ED9-4422-B1FD-22B75BF7DDBC}", "<script src=\'/smasb2b/js/htmlDataSet.js\'></script>");
			//InnertScript("{F3AE6520-1ED9-4422-B1FD-22B75BF7DDBD}", "<script src='/smasb2b/js/string.js'></script>")
			InnertScript("{F3AE6520-1ED9-4422-B1FD-22B75BF7DDBE}", "<script src=\'/smasb2b/js/GenerateXML.js\'></script>");
			InnertScript("{F3AE6520-1ED9-4422-B1FD-22B75BF7DDBF}", "<script src=\'/smasb2b/js/DataGrid.js\'></script>");
			//InnertScript("{F3AE6520-1ED9-4422-B1FD-22B75BF7DDBG}", "<script src='/smasb2b/js/ErrHandler.js'></script>")
			InnertScript("{F3AE6520-1ED9-4422-B1FD-22B75BF7DDBH}", "<script src=\'/smasb2b/js/ErrMsg.js\'></script>");
            
			
			if (!(Request["IsReSubmit"] == null))
			{
				if (Request["IsReSubmit"] == "Y")
				{
					IsReSubmit = true;
				}
			}
			//清除IE所catch之暫存檔
			Response.Cache.SetNoServerCaching();
			
			base.OnLoad(e);
		}
		
		////加入Script file
		public void InnertScript(string InnerKey, string InnertText)
		{
			
			if (!Page.IsClientScriptBlockRegistered(InnerKey))
			{
				Page.RegisterClientScriptBlock(InnerKey, InnertText);
			}
			
		}
		
		//產生多國語言控制器
		public ResourceManager GetResourceManager()
		{
			if (System.Convert.ToString(Session["langauage"]) == "zh-tw")
			{
				oldChar = "eng";
				newChar = "chin";
			}
			else
			{
				oldChar = "chin";
				newChar = "eng";
			}
			return new ResourceManager(System.Convert.ToString("smasb2b." + System.Convert.ToString(Session["langauage"])), System.Reflection.Assembly.GetExecutingAssembly());
		}
		
		protected override void OnUnload(System.EventArgs e)
		{
			rm = null;
			base.Dispose();
			Page.Dispose();
			base.OnUnload(e);
		}
		
		ResourceManager rm;
		
		public void TransformLanguage(Control FormControl)
		{
			Control ControlItem = default(Control);
			int i = 0;
			try
			{
				foreach (Control tempLoopVar_ControlItem in FormControl.Controls)
				{
					ControlItem = tempLoopVar_ControlItem;
					switch (ControlItem.GetType().Name)
					{
						case "Label":
                            ((Label)ControlItem).Text = rm.GetString(((Label)ControlItem).ID.Substring(3).ToUpper());
							break;
						case "HtmlInputButton":
                            ((HtmlInputButton)ControlItem).Value = rm.GetString(System.Convert.ToString(((HtmlInputButton)ControlItem).ID.ToUpper()));
							break;
						case "ClientButtonCtrl":
                            ((ClientButtonCtrl)ControlItem).Value = rm.GetString(((ClientButtonCtrl)ControlItem).ID.ToUpper());
							break;
						case "SubmitButtonCtrl":
                            ((SubmitButtonCtrl)ControlItem).Text = rm.GetString(System.Convert.ToString(((SubmitButtonCtrl)ControlItem).ID.ToUpper()));
							if (System.Convert.ToString(Session["langauage"]) == "zh-tw")
							{
                                ((SubmitButtonCtrl)ControlItem).Attributes["class"] = ((SubmitButtonCtrl)ControlItem).ID;
							}
							else
							{
                                ((SubmitButtonCtrl)ControlItem).Attributes["class"] = ((SubmitButtonCtrl)ControlItem).ID + "_e";
							}
							break;
						case "HtmlImage":
                            ((HtmlImage)ControlItem).Src = System.Convert.ToString(((HtmlImage)ControlItem).Src.ToLower().Replace(oldChar, newChar));
							break;
						case "HtmlInputImage":
                            ((HtmlInputImage)ControlItem).Src = System.Convert.ToString(((HtmlInputImage)ControlItem).Src.ToLower().Replace(oldChar, newChar));
							break;
						case "HtmlTable":
                            TransformLanguage((HtmlTable)ControlItem);
							break;
						case "HtmlTableRow":
                            TransformLanguage((HtmlTableRow)ControlItem);
							break;
						case "HtmlTableCell":
                            TransformLanguage((HtmlTableCell)ControlItem);
							break;
						case "HtmlGenericControl":
                            TransformLanguage((HtmlGenericControl)ControlItem);
							break;
						case "top_ascx":
                            TransformLanguage((smasb2b.top)ControlItem);
							break;
						case "left_ascx":
                            TransformLanguage((smasb2b.left)ControlItem);
							break;
						case "PurchaseBulletin_ascx":
                            TransformLanguage((smasb2b.PurchaseBulletin)ControlItem);
							break;
						case "RadioButtonList":
                            RadioButtonList radButton = (RadioButtonList)ControlItem;
							for (i = 0; i <= radButton.Items.Count - 1; i++)
							{
								radButton.Items[i].Text = rm.GetString(radButton.ID.Substring(3).ToUpper() + "_" + i.ToString());
							}
							break;
					}
				}
			}
			catch (Exception ex)
			{
				throw (ex);
			}
			
		}
		public VENDOR CreateVENDOR(string VENDOR_ID)
		{
			VENDOR OnVendor = new VENDOR();
			DataSet ReturnDS = default(DataSet);
			string SelectCommand = "";
            ArrayList m_arrParam = new ArrayList();
            dbAccess dba = new dbAccess();
			//Modi by JoeChou 針對松山海關進行特別判斷 2013/01/07 , 解決 TSA_CUSTOM 不定時帳號資料被刪除之Bug
			if (VENDOR_ID != "TSA_CUSTOM")
			{
                //Tony : 1.修改SQL語法使用參數，不組字串
				//SelectCommand = string.Format("SELECT * FROM V_VND_VENDOR WHERE PK_VENDOR_NO= \'{0}\'", VENDOR_ID.Replace("\'", "\'\'"));
                SelectCommand ="SELECT * FROM V_VND_VENDOR WHERE PK_VENDOR_NO= :VENDOR_ID";

			}
			else
			{
                //Tony : 1.修改SQL語法使用參數，不組字串
				//SelectCommand = string.Format("SELECT * FROM V_VND_VENDOR_TSA WHERE PK_VENDOR_NO= \'{0}\'", VENDOR_ID.Replace("\'", "\'\'"));
                SelectCommand = "SELECT * FROM V_VND_VENDOR_TSA WHERE PK_VENDOR_NO= :VENDOR_ID";
			}
			
			try
			{
                //Tony : 2.設定動態參數物件
                m_arrParam.Add(dba.GetOracleParam(":VENDOR_ID", VENDOR_ID.Replace("\'", "\'\'")));

				DataBase DataBase = new DataBase();
                //Tony : 3.修改執行方法Overload
				//ReturnDS = DataBase.Query_CLASS(SelectCommand, "VND_B2B_VENDOR");
                ReturnDS = DataBase.Query_CLASS(SelectCommand, "VND_B2B_VENDOR",m_arrParam);

				int Row = 0;
				
				if (!(ReturnDS == null) && ReturnDS.Tables["info"].Rows[0]["ReturnCode"] != "100" && ReturnDS.Tables["info"].Rows[0]["ReturnCode"] != "999")
				{
					Row = System.Convert.ToInt32(ReturnDS.Tables["VND_B2B_VENDOR"].Rows.Count - 1);
					OnVendor.IsAutouth = true;
					//功用參數設定
					OnVendor.VENDOR_NO = ReturnDS.Tables["VND_B2B_VENDOR"].Rows[Row]["PK_VENDOR_NO"].ToString();
					OnVendor.PASSWORD = ReturnDS.Tables["VND_B2B_VENDOR"].Rows[Row]["VENDOR_PWD"].ToString();
					OnVendor.B2B_STATUS = ReturnDS.Tables["VND_B2B_VENDOR"].Rows[Row]["B2B_STATUS"].ToString();
					OnVendor.B2B_FLAG_STATUS = ReturnDS.Tables["VND_B2B_VENDOR"].Rows[Row]["B2B_FLAG_STATUS"].ToString();
					OnVendor.PW_STATUS = ReturnDS.Tables["VND_B2B_VENDOR"].Rows[Row]["PW_STATUS"].ToString();
					OnVendor.VENDOR_STATUS = ReturnDS.Tables["VND_B2B_VENDOR"].Rows[Row]["VENDOR_STATUS"].ToString();
					OnVendor.VENDOR_KIND = ReturnDS.Tables["VND_B2B_VENDOR"].Rows[Row]["B2B_VENDOR_KIND"].ToString();
					
					//判斷是否為正式廠商
					if (OnVendor.B2B_STATUS == "0" || OnVendor.B2B_STATUS == "")
					{
						//取得VND_VENDOR資料
						OnVendor.NAME = ReturnDS.Tables["VND_B2B_VENDOR"].Rows[Row]["VENDOR_NAME_CHINESE"].ToString();
						OnVendor.ENGLISH_NAME = ReturnDS.Tables["VND_B2B_VENDOR"].Rows[Row]["VENDOR_NAME_ENGLISH"].ToString();
						OnVendor.VENDOR_TYPE = ReturnDS.Tables["VND_B2B_VENDOR"].Rows[Row]["VND_VENDOR_TYPE"].ToString();
						OnVendor.E_MAIL1 = ReturnDS.Tables["VND_B2B_VENDOR"].Rows[Row]["E_MAIL1"].ToString();
						OnVendor.E_MAIL2 = ReturnDS.Tables["VND_B2B_VENDOR"].Rows[Row]["E_MAIL2"].ToString();
						OnVendor.E_MAIL3 = ReturnDS.Tables["VND_B2B_VENDOR"].Rows[Row]["E_MAIL3"].ToString();
						OnVendor.B2BE_MAIL1 = ReturnDS.Tables["VND_B2B_VENDOR"].Rows[Row]["b2b_e_mail1"].ToString();
						OnVendor.B2BE_MAIL2 = ReturnDS.Tables["VND_B2B_VENDOR"].Rows[Row]["b2b_e_mail2"].ToString();
						OnVendor.B2BE_MAIL3 = ReturnDS.Tables["VND_B2B_VENDOR"].Rows[Row]["b2b_e_mail3"].ToString();
						
						OnVendor.CURRENCY_TYPE = ReturnDS.Tables["VND_B2B_VENDOR"].Rows[Row]["CURRENCY_TYPE"].ToString();
					}
					else
					{
						//取得B2B_VENDOR資料
						OnVendor.NAME = ReturnDS.Tables["VND_B2B_VENDOR"].Rows[Row]["B2B_VENDOR_NAME_CHINESE"].ToString();
						OnVendor.ENGLISH_NAME = ReturnDS.Tables["VND_B2B_VENDOR"].Rows[Row]["B2B_VENDOR_NAME_ENGLISH"].ToString();
						OnVendor.VENDOR_TYPE = ReturnDS.Tables["VND_B2B_VENDOR"].Rows[Row]["B2B_VENDOR_TYPE"].ToString();
						OnVendor.E_MAIL1 = ReturnDS.Tables["VND_B2B_VENDOR"].Rows[Row]["E_MAIL1"].ToString();
						OnVendor.E_MAIL2 = ReturnDS.Tables["VND_B2B_VENDOR"].Rows[Row]["E_MAIL2"].ToString();
						OnVendor.E_MAIL3 = ReturnDS.Tables["VND_B2B_VENDOR"].Rows[Row]["E_MAIL3"].ToString();
						OnVendor.B2BE_MAIL1 = ReturnDS.Tables["VND_B2B_VENDOR"].Rows[Row]["b2b_e_mail1"].ToString();
						OnVendor.B2BE_MAIL2 = ReturnDS.Tables["VND_B2B_VENDOR"].Rows[Row]["b2b_e_mail2"].ToString();
						OnVendor.B2BE_MAIL3 = ReturnDS.Tables["VND_B2B_VENDOR"].Rows[Row]["b2b_e_mail3"].ToString();
						OnVendor.CURRENCY_TYPE = ReturnDS.Tables["VND_B2B_VENDOR"].Rows[Row]["B2B_CURRENCY_TYPE"].ToString();
					}
				}
				else
				{
					OnVendor.IsAutouth = false;
				}
			}
			catch (Exception ex)
			{
				throw (ex);
			}
			finally
			{
				ReturnDS.Dispose();
			}
			return OnVendor;
		}

        public VENDOR GetLoginUser()
		{
            VENDOR LoginUser = null;
			if (!(Session["LoginUser"] == null))
			{
                LoginUser = ((VENDOR)(Session["LoginUser"]));
			}
			else //新增判斷session 被清除時導入首頁
			{
				InnerScript("location.href=\'/smasb2b/default.aspx\'");
			}
            return LoginUser;
		}

        public string GetLoginUser_Vendor_Kind()
		{
            string VENDOR_KIND = string.Empty;
			if (!(Session["LoginUser"] == null))
			{
                VENDOR_KIND = ((VENDOR)(Session["LoginUser"])).VENDOR_KIND;				
			}
            return VENDOR_KIND;
		}
		
		public string GetLanguage()
		{
			return System.Convert.ToString(Session["langauage"]);
		}
		public void InnerScript(string StringScript)
		{
			if (!this.IsStartupScriptRegistered("errMessage"))
			{
				this.RegisterStartupScript("errMessage", "<script language=\"javascript\">" + StringScript + "</script>");
			}
		}
		
		public void showException(string message)
		{
			if (!this.IsStartupScriptRegistered("errMessage"))
			{
				this.RegisterStartupScript("errMessage", "<script language=\"javascript\"> alert(\"" + message.Replace("\r", "").Replace("。", "").Replace("\n", "") + "\");window.returnValue = false;</script>");
			}
		}
		
		public void showException(Page TargetPage, string message)
		{
			if (!TargetPage.IsStartupScriptRegistered("errMessage"))
			{
				TargetPage.RegisterStartupScript("errMessage", "<script language=\"javascript\"> alert(\"" + message.Replace("\r", "").Replace("。", "").Replace("\n", "") + "\");window.returnValue = false;</script>");
			}
		}
		
		public void showDownFile(string message, string FilePath)
		{
			if (!Page.IsStartupScriptRegistered("downFile"))
			{
				Page.RegisterStartupScript("downFile", "<script language=\"javascript\">window.open (\'" + FilePath + "\', \'down\', \'height=0, width=0, top=1000, left=1000, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=n o, status=no\');</script>");
			}
		}
		
		public void regScript(DataSet ds, string action, string msg = "", string SMAS_FLAG = "")
		{
			//  Dim OnUser As Employee = LoginUser()
			string strResult = System.Convert.ToString(ds.Tables[0].Rows[0]["TransResult"].ToString());
			string strMessage = System.Convert.ToString(ds.Tables[0].Rows[0]["Message"].ToString());
			// Dim OnUser As VENDOR = GetLoginUser()
			string strSuccess = "";
			string strFail = "";
			string strClose = "";
			try
			{
				
				
				switch (action)
				{
					case "del":
						if (Session["langauage"] == "zh-tw")
						{
							strSuccess = "刪除成功!";
							strFail = "刪除失敗!\\n";
						}
						else if (Session["langauage"] == "zh-en")
						{
							strSuccess = "DELETE SUCCESS !";
							strFail = "DELETE FAIL !\\n";
						}
                        //strClose = "window.dialogArguments.FN_ReSubmit();this.close();";
                        //strClose = "window.opener.location.reload(true); this.close();";
                        //strClose = "window.opener.reload(); this.close();";
                        //strClose = "window.opener.document.forms[0].submit(); this.close();";
                        //strClose = "window.opener.history.go(0); window.opener.document.execCommand('Refresh'); this.close();";
                        strClose = "FN_ReSubmit();this.close();";


						break;
						
					default:
						if (Session["langauage"] == "zh-tw")
						{
							strSuccess = "存檔成功!";
							strFail = "存檔失敗!\\n";
						}
						else if (Session["langauage"] == "zh-en")
						{
							strSuccess = "SAVE SUCCESS !";
							strFail = "SAVE FAIL !\\n";
						}
						
						if (action == "upd")
						{
							if (SMAS_FLAG == "")
							{
                                //strClose = "window.dialogArguments.FN_ReSubmit();this.close();";
                                //strClose = "window.opener.location.reload(true); this.close();";
                                //strClose = "window.opener.reload(); this.close();";
                                //strClose = "window.opener.document.forms[0].submit(); this.close();";
                                //strClose = "window.opener.history.go(0); window.opener.document.execCommand('Refresh'); this.close();";
                                strClose = "FN_ReSubmit();this.close();";


                                //
                                //opener.doSubmit('REFRESH')
							}
							
						}
						break;
				}
				// 判斷交易結果
				if (strResult == "T")
				{
					if (!this.IsStartupScriptRegistered("Result"))
					{
						
						//If msg = "VendorMaintain" Then
						//    Me.RegisterStartupScript("Result", "<script language=""javascript""> alert('" & msg & strSuccess & "');window.navigate(""../evaair.aspx"")" & strClose & " </script>")
						//Else
						this.RegisterStartupScript("Result", "<script language=\"javascript\"> alert(\'" + msg + strSuccess + "\');" + strClose + " </script>");
						//  End If
						
					}
				}
				else if (strResult == "")
				{
					if (!this.IsStartupScriptRegistered("Result"))
					{
						this.RegisterStartupScript("Result", "<script language=\"javascript\">window.returnValue = false;</script>");
					}
				}
				else if (strResult == "F")
				{
					if (!this.IsStartupScriptRegistered("Result"))
					{
						this.RegisterStartupScript("Result", "<script language=\"javascript\"> alert(\'" + msg + strFail + strMessage + "\');window.returnValue = false; </script>");
					}
				}
			}
			catch (Exception ex)
			{
				showException(ex.Message);
			}
			finally
			{
			}
		}
		
		//將資料呈現於畫面
		public void DataGrid_Bind(HtmlTable DataGrid, ArrayList ArrKey, DataTable DataSource)
		{
            HtmlTableRow tr = (HtmlTableRow)(DataGrid.FindControl("DataGrid_head"));
			int i = 0;
			int j = 0;
			int k = 0;
			string Url = "";
			string className = "";
			ResourceManager rm = GetResourceManager();
			for (i = 0; i <= DataSource.Rows.Count - 1; i++)
			{
				HtmlTableRow htr = new HtmlTableRow();
				if (i % 2 == 0)
				{
					className = "evenRow";
				}
				else
				{
					className = "oddRow";
				}
				htr.Attributes.Add("class", className);
				DataGrid.Rows.Add(htr);
				for (j = 0; j <= tr.Cells.Count - 1; j++)
				{
					HtmlTableCell hd = new HtmlTableCell();
					switch (tr.Cells[j].Attributes["class"].ToLower())
					{
						case "link":
							Url = string.Format("{0}?action_type={1}&GUID={2}", tr.Cells[j].Attributes["url"].ToString(), tr.Cells[j].ID, Guid.NewGuid());
							for (k = 0; k <= ArrKey.Count - 1; k++)
							{
								Url += "&" + ArrKey[k] + "=" + DataSource.Rows[i][ArrKey[k].ToString()].ToString();
							}
							
							hd.Width = tr.Cells[j].Width;
							hd.InnerHtml = string.Format("<a href=\"javascript:window.showModalDialog(\'{0}\',null,\'{1}\', true)\">{2}</a>", Url, "dialogWidth=800px;dialogHeight=740px;center=yes;border=thin;help=no;status=no;resizable=no;", rm.GetString(System.Convert.ToString(tr.Cells[j].ID)));
							break;
						case "tdtitle":
							hd.Width = tr.Cells[j].Width;
							hd.Align = tr.Cells[j].Align;
							hd.Attributes.Add("class", "detail");
							hd.InnerText = System.Convert.ToString(DataSource.Rows[i][tr.Cells[j].Controls[1].ID.Replace("lbl", "")].ToString());
							break;
					}
					DataGrid.Rows[DataGrid.Rows.Count - 1].Cells.Add(hd);
				}
			}
			
		}
		
		public void ControlPageButton(HtmlTableRow DataGrid_Foot)
		{
			//Dim FirstButton As System.Web.UI.WebControls.ImageButton = CType(DataGrid_Foot.FindControl("btnFirst"), System.Web.UI.WebControls.ImageButton)
            System.Web.UI.WebControls.ImageButton PrevButton = (System.Web.UI.WebControls.ImageButton)(DataGrid_Foot.FindControl("btnPrev"));
            System.Web.UI.WebControls.ImageButton NextButton = (System.Web.UI.WebControls.ImageButton)(DataGrid_Foot.FindControl("btnNext"));
			// Dim LastButton As System.Web.UI.WebControls.ImageButton = CType(DataGrid_Foot.FindControl("btnLast"), System.Web.UI.WebControls.ImageButton)
            System.Web.UI.WebControls.ImageButton GoButton = (System.Web.UI.WebControls.ImageButton)(DataGrid_Foot.FindControl("btnGo"));
            ddscControlLibrary.InputBoxCtrl PageIndex = (ddscControlLibrary.InputBoxCtrl)(DataGrid_Foot.FindControl("PageIndex"));
            ddscControlLibrary.InputBoxCtrl PageCount = (ddscControlLibrary.InputBoxCtrl)(DataGrid_Foot.FindControl("PageCount"));
			int count = int.Parse(PageCount.Text);
			int index = int.Parse(PageIndex.Text);
			
			// .FirstButton.Enabled = True
			PrevButton.Enabled = true;
			NextButton.Enabled = true;
			// .LastButton.Enabled = True
			GoButton.Enabled = true;
			if (count == index)
			{
				NextButton.Enabled = false;
				// .LastButton.Enabled = False
			}
			if (index == 1)
			{
				// FirstButton.Enabled = False
				PrevButton.Enabled = false;
			}
			if (count == 0)
			{
				// FirstButton.Enabled = False
				PrevButton.Enabled = false;
				NextButton.Enabled = false;
				// LastButton.Enabled = False
				GoButton.Enabled = false;
				PageIndex.EnableView = true;
			}
			
		}
		//create by titan
		//判斷資料庫是否連線
		public void PaseConnect()
		{
			//Ken 20140627
			dbConnection dbc = new dbConnection();
			string strState;
			System.Data.OracleClient.OracleConnection cn = dbc.getOracleClientConnection();
			try
			{
				cn.Open();
				strState = cn.State.ToString();
				if (cn.State == ConnectionState.Open)
				{
					cn.Close();
				}
			}
			catch (Exception)
			{
				cn.Close();
				cn.Dispose();
				Response.Redirect("ErrHandler.aspx?ErrMsg=" + rm.GetString("MSG048"));
			}
			
		}
		
		//*********************************************************************
		//
		// SentHtmlMail() 函式
		//
		// 公用函式，傳入Mail之主題、收件者、寄件者、內文，後送出電子郵件
		//
		//*********************************************************************
		public void SentHtmlMail(string MailSubject, string MailTo, string MailCc, string MailBcc, string MailFrom, 
			string MailBody, string MailAccount, string MailPass, 
			string SMTP)
		{
            MailMessage Message = new MailMessage(MailFrom, MailTo, MailSubject, MailBody);
            Message.CC.Add(new MailAddress(MailCc));
            Message.Bcc.Add(new MailAddress(MailBcc));			
			Message.BodyEncoding = System.Text.Encoding.UTF8;
			Message.IsBodyHtml = true;			
			//SMTP認證帳號
			//Message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", txtID.Text)
			//SMTP認證密碼
			// Message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", txtPW.Text)
            SmtpClient client = new SmtpClient(SMTP);
            client.Send(Message);			
		}
		
		
		
	}
	
}
